package com.example.service;

import com.example.common.DubboPracticeConstants;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.rpc.RpcContext;

/**
 * @author zhouyp
 * @program dubbo-practice
 * @description
 * @create 2020-07-08
 */
public class ServiceImpl implements CommonService {

	@Override
	public void sayHello() {
		int port = RpcContext.getContext().getLocalPort();
		String host = RpcContext.getContext().getLocalHost();
		String attachment = RpcContext.getContext()
				.getAttachment(DubboPracticeConstants.TRANSPORT_IP_KEY);
		String format = String.format("当前ip和端口分别是:[%s-%d],dubbo传递过来的ip为:[%s]",
				host, port, attachment);
		System.out.println(format);
	}

}
